<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="cn">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=6.0.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=6.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=6.0.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.0.0" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta property="og:type" content="website">
<meta property="og:title" content="categories">
<meta property="og:url" content="http://yoursite.com/categories/index.html">
<meta property="og:site_name" content="hill&#39;s blog">
<meta property="og:locale" content="cn">
<meta property="article:published_time" content="2017-07-10T08:36:26.000Z">
<meta property="article:modified_time" content="2021-02-25T04:04:48.836Z">
<meta property="article:author" content="heyaojia">
<meta name="twitter:card" content="summary">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '6.0.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/categories/"/>





  <title>Go/Go语言-基础 | hill's blog</title>
  








<meta name="generator" content="Hexo 4.2.1"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="cn">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">hill's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/02/25/Go/Go%E8%AF%AD%E8%A8%80-%E5%9F%BA%E7%A1%80/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="heyaojia">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="hill's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Go/Go语言-基础</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2021-02-25T12:04:48+08:00">2021-02-25</time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="GO语言-基础学习"><a href="#GO语言-基础学习" class="headerlink" title="GO语言-基础学习"></a>GO语言-基础学习</h3><h4 id="1-变量-amp-amp-常量"><a href="#1-变量-amp-amp-常量" class="headerlink" title="1. 变量&amp;&amp;常量"></a>1. 变量&amp;&amp;常量</h4><hr>
<a id="more"></a>

<ol>
<li>常量</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 单个定义</span></span><br><span class="line">	<span class="keyword">var</span> v1 <span class="keyword">int</span></span><br><span class="line">	<span class="comment">// 批量定义</span></span><br><span class="line">	<span class="keyword">var</span> (</span><br><span class="line">		v2 <span class="keyword">int</span></span><br><span class="line">		v3 <span class="keyword">string</span></span><br><span class="line">	)</span><br><span class="line">	<span class="comment">// 或者这样定义</span></span><br><span class="line">	<span class="keyword">var</span> v4, v5 <span class="keyword">int</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 变量初始化</span></span><br><span class="line">	v1 = <span class="number">10</span></span><br><span class="line">	v2 = <span class="number">20</span></span><br><span class="line">	v3 = <span class="string">"你好，hill，这里是go语言学习"</span></span><br><span class="line">	v4 = <span class="number">1</span></span><br><span class="line">	v5 = <span class="number">0</span></span><br><span class="line"></span><br><span class="line">* golang中，变量不初始化会报错，一个叫做<span class="keyword">var</span> unused的错，跟Eralng类似</span><br><span class="line"></span><br><span class="line"><span class="comment">// 类型推导</span></span><br><span class="line">	<span class="keyword">var</span> v6 = <span class="string">"我不需要定义类型，也知道我是string"</span></span><br><span class="line">	fmt.Printf(<span class="string">"v6 = %s"</span>, v6)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 短变量声明</span></span><br><span class="line">	v7 := <span class="string">"只能在函数内部定义"</span></span><br><span class="line">	fmt.Printf(<span class="string">"v7 = %s"</span>, v7)</span><br><span class="line"></span><br><span class="line"><span class="comment">//匿名变量</span></span><br><span class="line">	_, x := foo()</span><br><span class="line">	y, _ := foo()</span><br><span class="line">	fmt.Printf(<span class="string">"x = %s"</span>, x)</span><br><span class="line">	fmt.Printf(<span class="string">"v7 = %d"</span>, y)</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>常量</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 单个定义</span></span><br><span class="line"><span class="keyword">const</span> c0 = <span class="number">999</span></span><br><span class="line"><span class="comment">// 多个定义</span></span><br><span class="line"><span class="keyword">const</span> (</span><br><span class="line">	c1 = <span class="number">0</span></span><br><span class="line">	c2</span><br><span class="line">	c3 = <span class="literal">iota</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<ul>
<li>c1后c2不赋值，默认与c1值相等</li>
<li>iota 常量计数器，const定义时为0， 定义一个 + 1</li>
</ul>
<p>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD</p>
<h4 id="2-数据结构"><a href="#2-数据结构" class="headerlink" title="2. 数据结构"></a>2. 数据结构</h4><hr>
<h5 id="x"><a href="#x" class="headerlink" title="x."></a>x.</h5><h5 id="x-数组"><a href="#x-数组" class="headerlink" title="x. 数组"></a>x. 数组</h5><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 声明</span></span><br><span class="line">	<span class="keyword">var</span> a1 [<span class="number">3</span>]<span class="keyword">bool</span></span><br><span class="line">	<span class="keyword">var</span> a2 [<span class="number">4</span>]<span class="keyword">bool</span></span><br><span class="line">	<span class="comment">// a1 == a2 错误，长度类型是一部分</span></span><br><span class="line">	fmt.Printf(<span class="string">"a1: %T, a2: %T \n"</span>, a1, a2)</span><br><span class="line">	<span class="comment">// 初始化数组（赋值）</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// ... 表示后面&#123;&#125;有多少个元素length就是多少</span></span><br><span class="line">	<span class="keyword">var</span> a3 = [<span class="number">3</span>]<span class="keyword">int</span>&#123;<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>&#125;</span><br><span class="line">	<span class="keyword">var</span> a4 = [...]<span class="keyword">int</span>&#123;<span class="number">1</span>, <span class="number">2</span>&#125;</span><br><span class="line">	fmt.Printf(<span class="string">"a3: %v \n"</span>, a3)</span><br><span class="line">	fmt.Printf(<span class="string">"a4: %v \n"</span>, a4)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">var</span> a5 = [...]<span class="keyword">int</span>&#123;<span class="number">1</span>: <span class="number">1</span>, <span class="number">4</span>: <span class="number">2</span>&#125; <span class="comment">// 指示下标</span></span><br><span class="line">	fmt.Printf(<span class="string">"a5: %v \n"</span>, a5)</span><br><span class="line"></span><br><span class="line">	<span class="comment">//遍历数组</span></span><br><span class="line">	<span class="comment">// ways1</span></span><br><span class="line">	tags := [...]<span class="keyword">string</span>&#123;<span class="string">"初级程序员"</span>, <span class="string">"中级程序员"</span>, <span class="string">"高级程序员"</span>&#125;</span><br><span class="line">	<span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="built_in">len</span>(tags); i++ &#123;</span><br><span class="line">		fmt.Printf(<span class="string">"%v"</span>, tags[i])</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="comment">// ways2</span></span><br><span class="line">	<span class="keyword">for</span> index, value := <span class="keyword">range</span> tags &#123;</span><br><span class="line">		fmt.Printf(<span class="string">"index %v, value %v \n"</span>, index, value)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//多维数组</span></span><br><span class="line">	d1 := [...][<span class="number">2</span>]<span class="keyword">string</span>&#123; <span class="comment">// 这里只有外层可以用...来表示多个，内层不允许用</span></span><br><span class="line">		&#123;<span class="string">"广州"</span>, <span class="string">"深圳"</span>&#125;,</span><br><span class="line">		<span class="comment">// &#123;"上海，“杭州", "武汉", "非洲"&#125;, //超出了下标会报错</span></span><br><span class="line">		&#123;<span class="string">"上海"</span>, <span class="string">"杭州"</span>&#125;,</span><br><span class="line">	&#125;</span><br><span class="line">	fmt.Printf(<span class="string">"%v"</span>, d1)</span><br><span class="line">	fmt.Printf(<span class="string">"%v \n"</span>, d1[<span class="number">0</span>][<span class="number">1</span>])</span><br><span class="line"></span><br><span class="line">	<span class="comment">//多维数组遍历</span></span><br><span class="line">	<span class="keyword">for</span> _, value := <span class="keyword">range</span> d1 &#123;</span><br><span class="line">		<span class="keyword">for</span> _, value2 := <span class="keyword">range</span> value &#123;</span><br><span class="line">			fmt.Printf(<span class="string">"%v \n"</span>, value2)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 数组是值类型，改变赋值，不会影响原有数据</span></span><br><span class="line">	<span class="comment">// 数组支持 == != 计算，指针用 *[n]T</span></span><br><span class="line">	<span class="comment">// z1 := [...]*int&#123;&#125;</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">/*</span></span><br><span class="line"><span class="comment">		练习：</span></span><br><span class="line"><span class="comment">		求数组[1, 3, 5, 7, 8]所有元素的和</span></span><br><span class="line"><span class="comment">		找出数组中和为指定值的两个元素的下标，比如从数组[1, 3, 5, 7, 8]中找出和为8的两个元素的下标分别为(0,3)和(1,2)。</span></span><br><span class="line"><span class="comment">	*/</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">var</span> t1 = []<span class="keyword">int</span>&#123;<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">8</span>&#125;</span><br><span class="line">	i := <span class="number">0</span></span><br><span class="line">	<span class="keyword">for</span> _, value := <span class="keyword">range</span> t1 &#123;</span><br><span class="line">		i = i + value</span><br><span class="line">	&#125;</span><br><span class="line">	fmt.Printf(<span class="string">"result = %v \n"</span>, i)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> i := <span class="number">0</span>; i &lt; <span class="built_in">len</span>(t1); i++ &#123;</span><br><span class="line">		<span class="keyword">for</span> j := i; j &lt; <span class="built_in">len</span>(t1); j++ &#123;</span><br><span class="line">			<span class="keyword">if</span> t1[i]+t1[j] == <span class="number">8</span> &#123;</span><br><span class="line">				fmt.Printf(<span class="string">"%v + %v = 8, 下标是 %v, %v \n"</span>, t1[i], t1[j], i, j)</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>

<h5 id="x-切片"><a href="#x-切片" class="headerlink" title="x. 切片"></a>x. 切片</h5><h4 id="3-流程控制"><a href="#3-流程控制" class="headerlink" title="3. 流程控制"></a>3. 流程控制</h4><hr>
<ol>
<li><p>for循环</p>
</li>
<li><p>if else</p>
</li>
<li><p>switch</p>
</li>
</ol>
<h4 id="4-函数"><a href="#4-函数" class="headerlink" title="4. 函数"></a>4. 函数</h4><hr>
<h4 id="5-包"><a href="#5-包" class="headerlink" title="5. 包"></a>5. 包</h4><hr>
<ol>
<li>包的导入路径是<code>$GOPATH/src/后面路径</code></li>
<li>一般来说，package是文件夹的名称，也可以不一样</li>
<li>如果package名跟文件.go名不一致，可以这样写<code>import alias &quot;src\xxx\xxx&quot;</code></li>
<li>保重标识符（变量名、函数名、结构体、接口、常量），凡是大写的都是public的，否则就是private的</li>
<li>不支持循环导入</li>
</ol>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 单个倒入导入</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">"fmt"</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 多个导入</span></span><br><span class="line"><span class="keyword">import</span>(</span><br><span class="line">  <span class="string">"fmt"</span></span><br><span class="line">  <span class="string">"os"</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<p>init（）：</p>
<ul>
<li><p>包导入的时候会自动执行一个叫init（）的函数</p>
</li>
<li><p>一个包里面只有一个init</p>
</li>
<li><p>init没有参数也没有返回值，也不能调用它</p>
</li>
<li><p>用于初始化</p>
</li>
</ul>
<h4 id="6-接口"><a href="#6-接口" class="headerlink" title="6. 接口"></a>6. 接口</h4><hr>
<ul>
<li><p>接口是一种类型</p>
</li>
<li><p>就是是想方法的清单</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">type mover interface&#123;</span><br><span class="line">  x x x(参数)（返回值）</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>接口的实现</p>
<ol>
<li><p>实现了接口的所有方法就实现了这个接口</p>
</li>
<li><p>实现了接口就可以当成这个接口的变量</p>
</li>
</ol>
</li>
<li><p>接口变量</p>
<ol>
<li><p>实现了一个都可以接受所有实现接口的变量</p>
</li>
<li><p>通常作为函数参数出现</p>
</li>
</ol>
</li>
<li><p>空接口</p>
<ol>
<li>所有的类型都实现了空接口</li>
</ol>
</li>
<li><p>接口底层</p>
<ol>
<li>动态类型</li>
<li>动态值</li>
</ol>
</li>
<li><p>类型断言</p>
<p>做类型断言的前提，一定要是一个接口变量</p>
<p><code>x.(T)</code></p>
</li>
</ul>
<h4 id="7-文件操作"><a href="#7-文件操作" class="headerlink" title="7. 文件操作"></a>7. 文件操作</h4><hr>
<p>​    url:  Go文件操作 这里需要单独抽出来写</p>
<ol>
<li>打开文件和关闭文件</li>
<li>读文件</li>
<li>写文件</li>
</ol>
<ul>
<li>在文件中插入</li>
</ul>
<h4 id="9-反射"><a href="#9-反射" class="headerlink" title="9. 反射"></a>9. 反射</h4><ul>
<li>先看看json转struct</li>
</ul>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">str := <span class="string">`&#123;"name":"周琳","age":17&#125;`</span></span><br><span class="line"><span class="keyword">var</span> p person</span><br><span class="line">json.Unmarshal([]<span class="keyword">byte</span>(str), &amp;p)</span><br><span class="line">fmt.Println(p.Name, p.Age)</span><br></pre></td></tr></table></figure>

<p>//TODO: 研究反射底层</p>
<ul>
<li>reflect包</li>
</ul>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">v := reflect.TypeOf(p)</span><br><span class="line">fmt.Println(v)</span><br><span class="line"></span><br><span class="line">反射中，反射还分为两个类型<span class="string">`种类`</span> 和<span class="string">`类型`</span></span><br><span class="line">fmt.Println(v.Name(), v.Kind())</span><br><span class="line"></span><br><span class="line"><span class="comment">//值的种类</span></span><br><span class="line">v := reflect.ValueOf(p)</span><br><span class="line">fmt.Println(v.Name(), v.Kind())</span><br><span class="line"></span><br><span class="line"><span class="comment">//isNil和isValid</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//结构体反射</span></span><br></pre></td></tr></table></figure>

<p>关于int 的定义</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> (</span><br><span class="line">	Invalid Kind = <span class="literal">iota</span></span><br><span class="line">	Bool</span><br><span class="line">	Int</span><br><span class="line">	Int8</span><br><span class="line">	Int16</span><br><span class="line">	Int32</span><br><span class="line">	Int64</span><br><span class="line">	Uint</span><br><span class="line">	Uint8</span><br><span class="line">	Uint16</span><br><span class="line">	Uint32</span><br><span class="line">	Uint64</span><br><span class="line">	Uintptr</span><br><span class="line">	Float32</span><br><span class="line">	Float64</span><br><span class="line">	Complex64</span><br><span class="line">	Complex128</span><br><span class="line">	Array</span><br><span class="line">	Chan</span><br><span class="line">	Func</span><br><span class="line">	Interface</span><br><span class="line">	Map</span><br><span class="line">	Ptr</span><br><span class="line">	Slice</span><br><span class="line">	String</span><br><span class="line">	Struct</span><br><span class="line">	UnsafePointer</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<h4 id="一些常用的go包："><a href="#一些常用的go包：" class="headerlink" title="# 一些常用的go包："></a># 一些常用的go包：</h4><hr>
<h5 id="1-fmt"><a href="#1-fmt" class="headerlink" title="1. fmt"></a>1. fmt</h5><figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fmt.<span class="built_in">println</span>(<span class="string">""</span>, <span class="keyword">var</span>) <span class="comment">// 自动换行</span></span><br></pre></td></tr></table></figure>

<h5 id="2-time包"><a href="#2-time包" class="headerlink" title="2.time包"></a>2.time包</h5><pre><code>now := time.Now()
fmt.Println(now.Year())
fmt.Println(now.Month())
fmt.Println(now.Day())
fmt.Println(now.Date())
fmt.Println(now.Hour())
fmt.Println(now.Minute())
fmt.Println(now.Second())
fmt.Println(now.Unix())
fmt.Println(now.UnixNano())
fmt.Println(time.Second)
fmt.Println(now.Add(time.Minute))
//定时器
// timer := time.Tick(time.Second)
// for t := range timer {
//     fmt.Println(t)
// }
//时间格式化
fmt.Println(now.Format(&quot;2020-02-21&quot;))</code></pre><h5 id=""><a href="#" class="headerlink" title=""></a></h5><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2021/02/25/Go/Go%E8%AF%AD%E8%A8%80-%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/" rel="next" title="Go/Go语言-并发编程">
                <i class="fa fa-chevron-left"></i> Go/Go语言-并发编程
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2021/02/25/%E5%B7%A5%E5%85%B7%E5%BA%94%E7%94%A8/%E8%99%9A%E6%8B%9F%E6%9C%BA%E7%9A%84%E4%BD%BF%E7%94%A8%E7%AC%94%E8%AE%B0/" rel="prev" title="虚拟机的使用笔记">
                虚拟机的使用笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">heyaojia</p>
              <p class="site-description motion-element" itemprop="description">游戏行业的一枚小鲜肉</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">21</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">categories</span>
                </a>
              </div>
            

            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="git@gitee.com:hillcool/hillcool.git" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-gitee"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#GO语言-基础学习"><span class="nav-number">1.</span> <span class="nav-text">GO语言-基础学习</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-变量-amp-amp-常量"><span class="nav-number">1.1.</span> <span class="nav-text">1. 变量&amp;&amp;常量</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-数据结构"><span class="nav-number">1.2.</span> <span class="nav-text">2. 数据结构</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#x"><span class="nav-number">1.2.1.</span> <span class="nav-text">x.</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#x-数组"><span class="nav-number">1.2.2.</span> <span class="nav-text">x. 数组</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#x-切片"><span class="nav-number">1.2.3.</span> <span class="nav-text">x. 切片</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-流程控制"><span class="nav-number">1.3.</span> <span class="nav-text">3. 流程控制</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4-函数"><span class="nav-number">1.4.</span> <span class="nav-text">4. 函数</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-包"><span class="nav-number">1.5.</span> <span class="nav-text">5. 包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-接口"><span class="nav-number">1.6.</span> <span class="nav-text">6. 接口</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-文件操作"><span class="nav-number">1.7.</span> <span class="nav-text">7. 文件操作</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9-反射"><span class="nav-number">1.8.</span> <span class="nav-text">9. 反射</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#一些常用的go包："><span class="nav-number">1.9.</span> <span class="nav-text"># 一些常用的go包：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-fmt"><span class="nav-number">1.9.1.</span> <span class="nav-text">1. fmt</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-time包"><span class="nav-number">1.9.2.</span> <span class="nav-text">2.time包</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#"><span class="nav-number">1.9.3.</span> <span class="nav-text"></span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">heyaojia</span>

  

  
</div>









        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
























  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=6.0.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=6.0.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=6.0.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=6.0.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=6.0.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=6.0.0"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
